package config

import "os"

// GetEnvironmentConfig 获取根据环境推导的配置
func (c *Config) GetEnvironmentConfig() *EnvironmentConfig {
	env := c.App.Environment

	// 支持环境变量覆盖
	if envVar := os.Getenv("APP_ENVIRONMENT"); envVar != "" {
		env = envVar
	}

	switch env {
	case "production":
		return &EnvironmentConfig{
			Debug:         false,
			LogLevel:      "info",
			LogOutput:     "file",
			LogFormat:     "json",
			AccessLog:     true,
			AccessLogBody: true,
		}
	default: // development
		return &EnvironmentConfig{
			Debug:         true,
			LogLevel:      "debug",
			LogOutput:     "console",
			LogFormat:     "console",
			AccessLog:     false, // 开发时不记录访问日志
			AccessLogBody: false,
		}
	}
}

// IsProduction 检查是否为生产环境
func (c *Config) IsProduction() bool {
	env := c.App.Environment
	if envVar := os.Getenv("APP_ENVIRONMENT"); envVar != "" {
		env = envVar
	}
	return env == "production"
}

// IsDevelopment 检查是否为开发环境
func (c *Config) IsDevelopment() bool {
	return !c.IsProduction()
}

// GetApp 获取应用配置
func (c *Config) GetApp() *AppConfig {
	return &c.App
}

// GetServer 获取服务器配置
func (c *Config) GetServer() *ServerConfig {
	return &c.Server
}

// GetDatabase 获取数据库配置
func (c *Config) GetDatabase() *DatabaseConfig {
	return &c.Database
}

// GetRedis 获取Redis配置
func (c *Config) GetRedis() *RedisConfig {
	return &c.Redis
}

// GetLog 获取日志配置
func (c *Config) GetLog() *LogConfig {
	return &c.Log
}

// GetMiddleware 获取中间件配置
func (c *Config) GetMiddleware() *MiddlewareConfig {
	return &c.Middleware
}

// GetCache 获取缓存配置
func (c *Config) GetCache() *CacheConfig {
	return &c.Cache
}
